package com.fkdx.webman.cron.service;

import com.fkdx.dao.entity.Task;
import com.fkdx.service.TaskService;
import com.fkdx.service.TicalService;
import com.fkdx.service.dto.TaskQueryReq;
import com.fkdx.service.dto.TaskQueryResp;
import com.fkdx.service.dto.TaskReq;
import com.fkdx.service.dto.TicalQueryResp;
import com.fkdx.webman.service.CardNumService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 零售云
 *
 * @author wsh
 * @date 2024-11-28 10:17
 **/
@Slf4j
@Component
public class CronServiceImpl {

  @Autowired
  private CardNumService cardNumService;
  @Autowired
  private TaskService taskService;
  @Autowired
  private TicalService ticalService;

  @Scheduled(cron = "0/10 * * * * *")
  public void exec() {
    Task r = new Task();
    //进行中
    r.setStatus(0);
    Task t = taskService.getTaskStatus(r);
    log.info("执行定时");
    if (t == null) {
      r.setStatus(2);
      t = taskService.getTaskStatus(r);
      if (t != null) {
        Integer tnum = taskService.getTaskCount(t.getPid());
        TicalQueryResp tir = ticalService.getTicalForm(t.getPid());
        int num = tnum * tir.getPrice();
        cardNumService.getCardNum(t.getUrl(), t.getPrice(), t.getId(), t.getType(), num);
        TaskReq tr = new TaskReq();
        tr.setId(t.getId());
        tr.setStatus(0);
        taskService.addTaskForm(tr);
      }

    }
  }

}
